<?php
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
session_name(SESSION);
session_start();

$myPdo = DbUtils::createPdoInst();
$page_id = MiscUtils::getParam('i', 0);

if (isset($_COOKIE['my_cart'])) {
  $_SESSION['my_cart'] = json_decode($_COOKIE['my_cart']);
}

if (!isset($_SESSION['my_cart'])) {
  $_SESSION['my_cart'] = array();
}
?>
<!DOCTYPE html>
<html>
  <head>
    <style>
      * {
        font-family: Trebuchet MS;
        font-size: 12px;
      }
      div.box {
        border: 1px solid #ddd;
        width: 460px;
        padding: 10px 0;
      }
      div.box a {
        color: #666;
        text-decoration: none;
        font-size: 13px;
      }
      div.box a:hover {
        text-decoration: underline;
      }
      div.title {
        font-size: 15px;
        margin-bottom: 5px;
        font-weight: bold;
      }
      table.lo td {
        vertical-align: top;
      }
      table.content {
        margin-left: 170px;
      }
      table.content td.img {
        padding-top: 5px;
      }
      table.content td.img img {
        width: 24px;
      }
      table.content td.text {
        padding-left: 10px;
        vertical-align: middle;
      }
    </style>
  </head>
  <body>
    <?php if (count($_SESSION['my_cart']) == 0) { ?>
    <div>Redirecting...</div>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(function() {
        parent.location.href = 'http://<?php echo URL . '?i=' . $page_id . '&script=index_cart'; ?>';
      });
    </script>
    <?php } else if (isset($_SESSION['index' . USER]) && $_SESSION['index' . USER]->id) { ?>
    <div>Redirecting...</div>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(function() {
        parent.location.href = 'http://<?php echo URL . '?i=' . $page_id . '&script=index_checkout'; ?>';
      });
    </script>
    <?php } else { ?>
    <table class="lo" cellpadding=0 cellspacing=0>
      <tr>
        <td>
          <div class="title">Buy anonymously</div>
          <div class="box">
            <table class="content" cellpadding=0 cellspacing=0 style="margin-left: 120px;">
              <tr>
                <td class="img"><img src="images/guest.png"></img></td>
                <td class="text"><a href="#" onclick="parent.location.href='http://<?php echo URL . '?i=' . $page_id . '&script=index_checkout'; ?>';">Continue without login</a></td>
              </tr>
            </table>
            <div style="margin: 5px 0 0 120px;"><b>Not recommended</b></div>
          </div>
        </td>
        <td style="padding-left: 10px;">
          <div class="title">I am a member</div>
          <div class="box">
            <table class="content" cellpadding=0 cellspacing=0>
              <tr>
                <td class="img"><img src="images/user.png"></img></td>
                <td class="text"><a href="#" onclick="parent.location.href='http://<?php echo URL . '?i=' . LOGIN_ID . '&url='; ?>' + encodeURIComponent(parent.document.URL);">Login</a></td>
              </tr>
            </table>
            <div style="margin: 5px 0 0 140px;"><b>Sign in for member discounts</b></div>
          </div>
          <div>&nbsp;</div>
          <div class="title">Not a member? Register in 2 minutes.</div>
          <div class="box">
            <table class="content" cellpadding=0 cellspacing=0 >
              <tr>
                <td class="img"><img src="images/reg.png"></img></td>
                <td class="text"><a href="#" onclick="parent.location.href='http://<?php echo URL . '?i=' . LOGIN_ID . '&init=register&url='; ?>' + encodeURIComponent(parent.document.URL);">Register Now</a></td>
              </tr>
            </table>
            <div style="margin: 5px 0 0 140px;"><b>Why to Register:</b></div>
            <ul style="margin: 5px 0 15px 140px;">
              <li>Member Discounts</li>
              <li>Easy Order Tracking</li>
              <li>Better Customer Service</li>
              <li>Special Offers</li>
            </ul>
          </div>
        </td>
      </tr>
    </table>
    <script>
    parent.document.title = parent.document.title.replace('Product', 'Login')
    </script>
    <?php } ?>
  </body>
</html>